home *** CD-ROM | disk | FTP | other *** search
-
- /*
- **
- ** $VER: fastprim.c 1.0 (6.9.1995)
- **
- ** Written by Roland Mainz, 1995
- **
- */
-
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
-
- #define TEST_TEST 1
-
- #define ARRAY_SIZE (1000000)
-
- unsigned long p[ ARRAY_SIZE ];
-
-
- int main( void )
- {
- unsigned long i,
- j,
- checkmax,
- isprim;
- unsigned long pa;
-
- pa = 0U;
- p[ pa ] = 2U; /* first entry */
-
- for( i = 3U ; pa < ARRAY_SIZE ; (i+= 2U) )
- {
- checkmax = ((unsigned short int)sqrt( (double)i )) + 1U;
-
- isprim = 1U;
-
- for( j = 0 ; j < pa ; j++ )
- {
- if( p[ j ] > checkmax )
- {
- break;
- }
-
- if( (i % p[ j ]) == 0U )
- {
- isprim = 0U;
- break;
- }
- }
-
- if( isprim == 1U )
- {
- #ifdef TEST_TEST
- static long strip_out = 0L;
- #endif /* TEST_TEST */
-
- pa++;
-
- p[ pa ] = i;
-
- #ifdef TEST_TEST
- if( (strip_out++ % 1000L) == 0L )
- #endif /* TEST_TEST */
-
- printf( "%ld\n", i );
- }
- }
-
- #ifdef TEST_TEST
- printf( "Done !\n" );
- #endif /* TEST_TEST */
-
- return( EXIT_SUCCESS );
- }
-
-